package com.xianyun.site.iblog.user.executor.handle.config;

import com.xianyun.site.iblog.common.core.exception.LoginTypeErrorException;
import com.xianyun.site.iblog.user.executor.handle.BaseLoginCheckHandle;
import com.xianyun.site.iblog.user.executor.handle.impl.AuthResultCheckHandle;
import com.xianyun.site.iblog.user.executor.handle.impl.IMobileCodeCheckHandle;
import com.xianyun.site.iblog.user.executor.handle.impl.IUserPasswordCheckHandle;

/**
 * 登录校验类型校验
 * @author mac_zyj
 */
public enum  HandleCheck {
    /**密码登录*/
    PASSWORD("用户名密码登录",new IUserPasswordCheckHandle(),0),
    /**手机验证码登录*/
    MOBILE_CODE("手机验证码登录",new IMobileCodeCheckHandle(),1),
    /**三方登录账户查询*/
    AUTH_LOGIN("三方登录", new AuthResultCheckHandle(),2);
    /**类型名称*/
    private final String typeName;
    /**登录处理Handle*/
    private final BaseLoginCheckHandle loginHandle;
    /**登录类型*/
    private final Integer loginType;

    HandleCheck(String typeName, BaseLoginCheckHandle loginHandle, Integer loginType) {
        this.typeName = typeName;
        this.loginHandle = loginHandle;
        this.loginType = loginType;
    }

    public String getTypeName() {
        return typeName;
    }

    public BaseLoginCheckHandle getLoginHandle() {
        return loginHandle;
    }

    public Integer getLoginType() {
        return loginType;
    }

    public static Class<? extends BaseLoginCheckHandle>getLoginHandleByType(int loginType){
        for (HandleCheck current:values()){
            if (current.getLoginType().equals(loginType)){
                return current.getLoginHandle().getClass();
            }
        }
        throw new LoginTypeErrorException("登录类型不存在");
    }
}
